package RecursiveSearcher;

/**
 * @ClassName LC2331
 * @Description 计算布尔二叉树的值
 * @Author ZJX
 * @Date 2024/9/12 20:08
 * @Version 1.0
 */

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode() {
    }

    TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

//    https://leetcode.cn/problems/evaluate-boolean-binary-tree/
public class LC2331 {
    public boolean evaluateTree(TreeNode root) {
        //        后序遍历 要知道左 右 再根据 根节点 判断
        if (root.left == null) return root.val == 0 ? false : true;

        boolean left = evaluateTree(root.left);
        boolean right = evaluateTree(root.right);

        return root.val == 2 ? left || right : left && right;
    }



}
